﻿using BasicData.Application.Input;
using BasicData.Application.Input.Supplier;
using BasicData.Application.Output;
using BasicData.Application.Services.Supplier;
using BasicData.Result;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BasicData.Api.Controllers
{
    /// <summary>
    /// 供应商管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SupplierController : ControllerBase
    {
        private readonly ISupplierServices _services;
        ILogger<SupplierController> _logger;

        public SupplierController(ISupplierServices services, ILogger<SupplierController> logger)
        {
            _services = services;
            _logger = logger;
        }
        /// <summary>
        /// 添加供应商
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> AddSupplier(SupplierInput input)
        {
            _logger.LogInformation("添加供应商");
            return _services.AddSupplier(input);
        }
        /// <summary>
        /// 删除供应商
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> DeleteSupplier(long id)
        {
            _logger.LogInformation("删除供应商");
            return _services.DeleteSupplier(id);
        }
        /// <summary>
        /// 获取供应商列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiPaging<SupplierOutput> GetSupplier([FromQuery] PageInput input)
        {
            _logger.LogInformation("获取供应商列表");
            return _services.GetSupplier(input);
        }
        /// <summary>
        /// 修改供应商
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> UpdateSupplier(UpdateSupplierInput input)
        {
            _logger.LogInformation("修改供应商");
            return _services.UpdateSupplier(input);
        }
    }
}
